<?php
@session_start();
include_once dirname(__FILE__)."/../../model/config.php";
		$_unite=new unite();
		$_indexation=new indexation();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["code_ue"])){$_unite->set_code_ue($_POST["code_ue"]);}
		if(isset($_POST["lib_unite"])){$_unite->set_lib_unite($_POST["lib_unite"]);}
		if(isset($_POST["nature_unite"])){$_unite->set_nature_unite($_POST["nature_unite"]);}
		if(isset($_POST["ECUE"])){$_unite->set_ECUE($_POST["ECUE"]);}
		if(isset($_POST["volume_cours"])){$_unite->set_volume_cours($_POST["volume_cours"]);}
		if(isset($_POST["volume_TP"])){$_unite->set_volume_TP($_POST["volume_TP"]);}
		if(isset($_POST["volume_TD"])){$_unite->set_volume_TD($_POST["volume_TD"]);}
		if(isset($_POST["coeifficient"])){$_unite->set_coeifficient($_POST["coeifficient"]);}
		if(isset($_POST["code_diplome"])){$_unite->set_code_diplome($_POST["code_diplome"]);}
		if(isset($_POST["code_niveau"])){$_unite->set_code_niveau($_POST["code_niveau"]);}
		if(isset($_POST["code_domaine"])){$_unite->set_code_domaine($_POST["code_domaine"]);}
		if(isset($_POST["date_soumission"])){$_unite->set_date_soumission($_POST["date_soumission"]);}
		if(isset($_POST["credit"])){$_unite->set_credit($_POST["credit"]);}
		if(isset($_POST["projet"])){$_unite->set_projet($_POST["projet"]);}
		if(isset($_POST["CIN"])){$_unite->set_CIN($_POST["CIN"]);}
		if(isset($_POST["date_depot_contenu"])){$_unite->set_date_depot_contenu($_POST["date_depot_contenu"]);}
		if(isset($_POST["code_mention"])){$_unite->set_code_mention($_POST["code_mention"]);}
		if(isset($_POST["specialite"])){$_unite->set_specialite($_POST["specialite"]);}
		if(isset($_POST["session"])){$_unite->set_session($_POST["session"]);}
		if(isset($_POST["date_decision"])){$_unite->set_date_decision($_POST["date_decision"]);}
		if(isset($_POST["decision"])){$_unite->set_decision($_POST["decision"]);}
		if(isset($_POST["observation_ue"])){$_unite->set_observation_ue($_POST["observation_ue"]);}
		if(isset($_POST["mail_sended"])){$_unite->set_mail_sended($_POST["mail_sended"]);}
		if(isset($_POST["nbr_ens"])){$_unite->set_nbr_ens($_POST["nbr_ens"]);}
		if(isset($_POST["decision_production"])){$_unite->set_decision_production($_POST["decision_production"]);}
		if(isset($_POST["date_decision_num"])){$_unite->set_date_decision_num($_POST["date_decision_num"]);}
		if(isset($_POST["date_decision_exp"])){$_unite->set_date_decision_exp($_POST["date_decision_exp"]);}
		if(isset($_POST["duree"])){$_unite->set_duree($_POST["duree"]);}
		if(isset($_POST["delai_jour"])){$_unite->set_delai_jour($_POST["delai_jour"]);}
		if(isset($_POST["validation_scientifique"])){$_unite->set_validation_scientifique($_POST["validation_scientifique"]);}
		if(isset($_POST["expRPL"])){$_unite->set_expRPL($_POST["expRPL"]);}
		if(isset($_POST["expMoodle"])){$_unite->set_expMoodle($_POST["expMoodle"]);}
		if(isset($_POST["etat_soumission"])){$_unite->set_etat_soumission($_POST["etat_soumission"]);}
		
		
		$res=$_unite->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["code_ue"])){
		$_unite->set_code_ue($_POST["code_ue"]);
		$res=$_unite->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["code_ue"])){$_unite->set_code_ue($_POST["code_ue"]);}
		if(isset($_POST["lib_unite"])){$_unite->set_lib_unite($_POST["lib_unite"]);}
		if(isset($_POST["nature_unite"])){$_unite->set_nature_unite($_POST["nature_unite"]);}
		if(isset($_POST["ECUE"])){$_unite->set_ECUE($_POST["ECUE"]);}
		if(isset($_POST["volume_cours"])){$_unite->set_volume_cours($_POST["volume_cours"]);}
		if(isset($_POST["volume_TP"])){$_unite->set_volume_TP($_POST["volume_TP"]);}
		if(isset($_POST["volume_TD"])){$_unite->set_volume_TD($_POST["volume_TD"]);}
		if(isset($_POST["coeifficient"])){$_unite->set_coeifficient($_POST["coeifficient"]);}
		if(isset($_POST["code_diplome"])){$_unite->set_code_diplome($_POST["code_diplome"]);}
		if(isset($_POST["code_niveau"])){$_unite->set_code_niveau($_POST["code_niveau"]);}
		if(isset($_POST["code_domaine"])){$_unite->set_code_domaine($_POST["code_domaine"]);}
		if(isset($_POST["date_soumission"])){$_unite->set_date_soumission($_POST["date_soumission"]);}
		if(isset($_POST["credit"])){$_unite->set_credit($_POST["credit"]);}
		if(isset($_POST["projet"])){$_unite->set_projet($_POST["projet"]);}
		if(isset($_POST["CIN"])){$_unite->set_CIN($_POST["CIN"]);}
		if(isset($_POST["date_depot_contenu"])){$_unite->set_date_depot_contenu($_POST["date_depot_contenu"]);}
		if(isset($_POST["code_mention"])){$_unite->set_code_mention($_POST["code_mention"]);}
		if(isset($_POST["specialite"])){$_unite->set_specialite($_POST["specialite"]);}
		if(isset($_POST["session"])){$_unite->set_session($_POST["session"]);}
		if(isset($_POST["date_decision"])){$_unite->set_date_decision($_POST["date_decision"]);}
		if(isset($_POST["decision"])){$_unite->set_decision($_POST["decision"]);}
		if(isset($_POST["observation_ue"])){$_unite->set_observation_ue($_POST["observation_ue"]);}
		if(isset($_POST["mail_sended"])){$_unite->set_mail_sended($_POST["mail_sended"]);}
		if(isset($_POST["nbr_ens"])){$_unite->set_nbr_ens($_POST["nbr_ens"]);}
		if(isset($_POST["decision_production"])){$_unite->set_decision_production($_POST["decision_production"]);}
		if(isset($_POST["date_decision_num"])){$_unite->set_date_decision_num($_POST["date_decision_num"]);}
		if(isset($_POST["date_decision_exp"])){$_unite->set_date_decision_exp($_POST["date_decision_exp"]);}
		if(isset($_POST["duree"])){$_unite->set_duree($_POST["duree"]);}
		if(isset($_POST["delai_jour"])){$_unite->set_delai_jour($_POST["delai_jour"]);}
		if(isset($_POST["validation_scientifique"])){$_unite->set_validation_scientifique($_POST["validation_scientifique"]);}
		if(isset($_POST["expRPL"])){$_unite->set_expRPL($_POST["expRPL"]);}
		if(isset($_POST["expMoodle"])){$_unite->set_expMoodle($_POST["expMoodle"]);}
		if(isset($_POST["etat_soumission"])){$_unite->set_etat_soumission($_POST["etat_soumission"]);}
		
		
		
		$res=$_unite->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

elseif($_POST["operation"]=="UPDATE1"){
		if(isset($_POST["code_ue"])){$_unite->set_code_ue($_POST["code_ue"]);}
		if(isset($_POST["lib_unite"])){$_unite->set_lib_unite($_POST["lib_unite"]);}
		if(isset($_POST["nature_unite"])){$_unite->set_nature_unite($_POST["nature_unite"]);}
		if(isset($_POST["ECUE"])){$_unite->set_ECUE($_POST["ECUE"]);}
		if(isset($_POST["volume_cours"])){$_unite->set_volume_cours($_POST["volume_cours"]);}
		if(isset($_POST["volume_TP"])){$_unite->set_volume_TP($_POST["volume_TP"]);}
		if(isset($_POST["volume_TD"])){$_unite->set_volume_TD($_POST["volume_TD"]);}
		if(isset($_POST["coeifficient"])){$_unite->set_coeifficient($_POST["coeifficient"]);}
		if(isset($_POST["code_diplome"])){$_unite->set_code_diplome($_POST["code_diplome"]);}
		if(isset($_POST["code_niveau"])){$_unite->set_code_niveau($_POST["code_niveau"]);}
		if(isset($_POST["code_domaine"])){$_unite->set_code_domaine($_POST["code_domaine"]);}
		if(isset($_POST["date_soumission"])){$_unite->set_date_soumission($_POST["date_soumission"]);}
		if(isset($_POST["credit"])){$_unite->set_credit($_POST["credit"]);}
		if(isset($_POST["projet"])){$_unite->set_projet($_POST["projet"]);}
		if(isset($_POST["CIN"])){$_unite->set_CIN($_POST["CIN"]);}
		if(isset($_POST["date_depot_contenu"])){$_unite->set_date_depot_contenu($_POST["date_depot_contenu"]);}
		if(isset($_POST["code_mention"])){$_unite->set_code_mention($_POST["code_mention"]);}
		if(isset($_POST["specialite"])){$_unite->set_specialite($_POST["specialite"]);}
		if(isset($_POST["session"])){$_unite->set_session($_POST["session"]);}
		if(isset($_POST["date_decision"])){$_unite->set_date_decision($_POST["date_decision"]);}
		if(isset($_POST["decision"])){$_unite->set_decision($_POST["decision"]);}
		if(isset($_POST["observation_ue"])){$_unite->set_observation_ue($_POST["observation_ue"]);}
		if(isset($_POST["mail_sended"])){$_unite->set_mail_sended($_POST["mail_sended"]);}
		if(isset($_POST["nbr_ens"])){$_unite->set_nbr_ens($_POST["nbr_ens"]);}
		if(isset($_POST["decision_production"])){$_unite->set_decision_production($_POST["decision_production"]);}
		if(isset($_POST["date_decision_num"])){$_unite->set_date_decision_num($_POST["date_decision_num"]);}
		if(isset($_POST["date_decision_exp"])){$_unite->set_date_decision_exp($_POST["date_decision_exp"]);}
		if(isset($_POST["duree"])){$_unite->set_duree($_POST["duree"]);}
		if(isset($_POST["delai_jour"])){$_unite->set_delai_jour($_POST["delai_jour"]);}
		if(isset($_POST["validation_scientifique"])){$_unite->set_validation_scientifique($_POST["validation_scientifique"]);}
		if(isset($_POST["expRPL"])){$_unite->set_expRPL($_POST["expRPL"]);}
		if(isset($_POST["expMoodle"])){$_unite->set_expMoodle($_POST["expMoodle"]);}
		if(isset($_POST["etat_soumission"])){$_unite->set_etat_soumission($_POST["etat_soumission"]);}
		
		/**************************************************************************************/
		
		if(isset($_POST["code_index"])){$_indexation->set_code_index($_POST["code_index"]);}
		if(isset($_POST["code_ue"])){$_indexation->set_code_ue($_POST["code_ue"]);}
		if(isset($_POST["titre"])){$_indexation->set_titre($_POST["titre"]);}
		if(isset($_POST["discipline"])){$_indexation->set_discipline($_POST["discipline"]);}
		if(isset($_POST["mots_cles"])){$_indexation->set_mots_cles($_POST["mots_cles"]);}
		if(isset($_POST["date_creation"])){$_indexation->set_date_creation($_POST["date_creation"]);}
		if(isset($_POST["public_cible"])){$_indexation->set_public_cible($_POST["public_cible"]);}
		if(isset($_POST["objectif"])){$_indexation->set_objectif($_POST["objectif"]);}
		if(isset($_POST["nature"])){$_indexation->set_nature($_POST["nature"]);}
		if(isset($_POST["description"])){$_indexation->set_description($_POST["description"]);}
		
		
		/**************************************************************************************/
		//$res1=$_indexation->UPDATE(); 
		$res=$_unite->UPDATE1(); 
        
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	$res=$_indexation->UPDATE(); 
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}


}
else{
	$constraint='';
	$limit=0;
	$start=0;
	$pagination='';
	if(isset($_POST["code_ue"]) && !empty($_POST["code_ue"])){
		$constraint.=" AND code_ue='".$_POST["code_ue"]."'";
	}

	if(isset($_POST["lib_unite"]) && !empty($_POST["lib_unite"])){
		$constraint.=" AND lib_unite='".$_POST["lib_unite"]."'";
	}

	if(isset($_POST["nature_unite"]) && !empty($_POST["nature_unite"])){
		$constraint.=" AND nature_unite='".$_POST["nature_unite"]."'";
	}

	if(isset($_POST["ECUE"]) && !empty($_POST["ECUE"])){
		$constraint.=" AND ECUE='".$_POST["ECUE"]."'";
	}

	if(isset($_POST["volume_cours"]) && !empty($_POST["volume_cours"])){
		$constraint.=" AND volume_cours='".$_POST["volume_cours"]."'";
	}

	if(isset($_POST["volume_TP"]) && !empty($_POST["volume_TP"])){
		$constraint.=" AND volume_TP='".$_POST["volume_TP"]."'";
	}

	if(isset($_POST["volume_TD"]) && !empty($_POST["volume_TD"])){
		$constraint.=" AND volume_TD='".$_POST["volume_TD"]."'";
	}

	if(isset($_POST["coeifficient"]) && !empty($_POST["coeifficient"])){
		$constraint.=" AND coeifficient='".$_POST["coeifficient"]."'";
	}

	if(isset($_POST["code_diplome"]) && !empty($_POST["code_diplome"])){
		$constraint.=" AND code_diplome='".$_POST["code_diplome"]."'";
	}

	if(isset($_POST["code_niveau"]) && !empty($_POST["code_niveau"])){
		$constraint.=" AND code_niveau='".$_POST["code_niveau"]."'";
	}

	if(isset($_POST["code_domaine"]) && !empty($_POST["code_domaine"])){
		$constraint.=" AND code_domaine='".$_POST["code_domaine"]."'";
	}

	if(isset($_POST["date_soumission"]) && !empty($_POST["date_soumission"])){
		$constraint.=" AND date_soumission='".$_POST["date_soumission"]."'";
	}

	if(isset($_POST["credit"]) && !empty($_POST["credit"])){
		$constraint.=" AND credit='".$_POST["credit"]."'";
	}

	if(isset($_POST["projet"]) && !empty($_POST["projet"])){
		$constraint.=" AND projet='".$_POST["projet"]."'";
	}

	

	if(isset($_POST["date_depot_contenu"]) && !empty($_POST["date_depot_contenu"])){
		$constraint.=" AND date_depot_contenu='".$_POST["date_depot_contenu"]."'";
	}

	if(isset($_POST["code_mention"]) && !empty($_POST["code_mention"])){
		$constraint.=" AND code_mention='".$_POST["code_mention"]."'";
	}

	if(isset($_POST["specialite"]) && !empty($_POST["specialite"])){
		$constraint.=" AND specialite='".$_POST["specialite"]."'";
	}

	if(isset($_POST["session"]) && !empty($_POST["session"])){
		$constraint.=" AND session='".$_POST["session"]."'";
	}

	if(isset($_POST["date_decision"]) && !empty($_POST["date_decision"])){
		$constraint.=" AND date_decision='".$_POST["date_decision"]."'";
	}

	if(isset($_POST["decision"]) && !empty($_POST["decision"])){
		$constraint.=" AND decision='".$_POST["decision"]."'";
	}

	if(isset($_POST["observation_ue"]) && !empty($_POST["observation_ue"])){
		$constraint.=" AND observation_ue='".$_POST["observation_ue"]."'";
	}

	if(isset($_POST["mail_sended"]) && !empty($_POST["mail_sended"])){
		$constraint.=" AND mail_sended='".$_POST["mail_sended"]."'";
	}

	if(isset($_POST["nbr_ens"]) && !empty($_POST["nbr_ens"])){
		$constraint.=" AND nbr_ens='".$_POST["nbr_ens"]."'";
	}

	if(isset($_POST["decision_production"]) && !empty($_POST["decision_production"])){
		$constraint.=" AND decision_production='".$_POST["decision_production"]."'";
	}

	if(isset($_POST["date_decision_num"]) && !empty($_POST["date_decision_num"])){
		$constraint.=" AND date_decision_num='".$_POST["date_decision_num"]."'";
	}

	if(isset($_POST["date_decision_exp"]) && !empty($_POST["date_decision_exp"])){
		$constraint.=" AND date_decision_exp='".$_POST["date_decision_exp"]."'";
	}

	if(isset($_POST["duree"]) && !empty($_POST["duree"])){
		$constraint.=" AND duree='".$_POST["duree"]."'";
	}

	if(isset($_POST["delai_jour"]) && !empty($_POST["delai_jour"])){
		$constraint.=" AND delai_jour='".$_POST["delai_jour"]."'";
	}

	if(isset($_POST["validation_scientifique"]) && !empty($_POST["validation_scientifique"])){
		$constraint.=" AND validation_scientifique='".$_POST["validation_scientifique"]."'";
	}

	if(isset($_POST["expRPL"]) && !empty($_POST["expRPL"])){
		$constraint.=" AND expRPL='".$_POST["expRPL"]."'";
	}

	if(isset($_POST["expMoodle"]) && !empty($_POST["expMoodle"])){
		$constraint.=" AND expMoodle='".$_POST["expMoodle"]."'";
	}
	if(isset($_POST["etat_soumission"]) && !empty($_POST["etat_soumission"])){
		$constraint.=" AND etat_soumission='".$_POST["etat_soumission"]."'";
	}
	
	
	
	

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
	 if(isset($_SESSION["cin"]) && !empty($_SESSION["cin"])){
		$constraint.=" AND CIN='".$_SESSION['cin']."'";
	}
	   $constraint.=" AND etat_soumission='2'";
	
		$res=$_unite->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_unite->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 $count=$_unite->countRowInTable();
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => $count,'result' => $data ));
	  	
	  }}
?>